package cqcvc.edu.cn.dao;

import cqcvc.edu.cn.base.BaseDao;
import cqcvc.edu.cn.entity.JobInfo;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class JobDao {

    public List<JobInfo> findAll(){
        Connection connection = BaseDao.getConn();
        try{
            Statement state = connection.createStatement();//容器
            String sql = "select * from job_info";
            ResultSet resultSet = state.executeQuery(sql);
            return getList(resultSet);
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    private List<JobInfo> getList(ResultSet resultSet){
        try {
            List<JobInfo> list = new ArrayList<>();
            while (resultSet.next()){
                JobInfo jobInfo = new JobInfo();

                jobInfo.setId(resultSet.getLong(1));
                jobInfo.setJobTitle(resultSet.getString(2));
                jobInfo.setJobDetail(resultSet.getString(3));
                jobInfo.setCreateDate(resultSet.getDate(4));
                jobInfo.setShowOrder(resultSet.getInt(5));
                jobInfo.setIfShow(resultSet.getString(6));
                list.add(jobInfo);
            }
            return list;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
